﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Clotho.Keyword {
	public partial class KeywordControl : Control {
		void init() {
			SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
			SetStyle(ControlStyles.UserPaint, true);
			BackColor = Color.White;
		}
		public KeywordControl() {
			init();
		}
		public KeywordControl(Clotho.Plot plot) {
			init();
			this.plot = plot;
		}
		public Clotho.Plot plot;
		Size avatar_size = new Size(20, 20);
		int avatar_space = 3;
		int Avatar_space {
			get {
				return avatar_space;
			}
			set {
				avatar_space = value;
				this.Refresh();
			}
		}
		public Size Avatar_size {
			get {
				return avatar_size;
			}
			set {
				avatar_size = value;
				this.Refresh();
			}
		}
		public event EventHandler<KeywordFeature> eKeywordClick;
		protected override void OnPaint(PaintEventArgs pe) {
			if (plot == null) {
				var g1 = pe.Graphics;
				base.OnPaint(pe);
				g1.FillEllipse(new SolidBrush(Color.Red),
					0, 0 * (avatar_size.Height + avatar_space),
					avatar_size.Width, avatar_size.Height); 
				g1.FillEllipse(new SolidBrush(Color.Green),
					0, 1 * (avatar_size.Height + avatar_space),
					avatar_size.Width, avatar_size.Height);
				g1.FillEllipse(new SolidBrush(Color.Yellow),
					0, 2 * (avatar_size.Height + avatar_space),
					avatar_size.Width, avatar_size.Height);
				return;
			}
			var g = pe.Graphics;
			int avatar_num = 0;
			base.OnPaint(pe);
			foreach (var kw in plot.Features) {
				if (kw is KeywordFeature) {
					var desc = plot.Nov.Base_plot.getFeature<KeywordDescFeature>(kw.Name);
					if (desc != null) {
						g.FillEllipse(new SolidBrush(desc.Backgrond_color), 
							0 , avatar_num* (avatar_size.Height+ avatar_space),
							avatar_size.Width, avatar_size.Height);
						avatar_num++;
					}
				}
			}
		}
	}
}
